extends Control

@onready var name_label = $Panel/MarginContainer/VBoxContainer/NameLabel
@onready var text_label = $Panel/MarginContainer/VBoxContainer/TextLabel

func _ready() -> void:
	# 连接对话管理器的信号
	DialogManager.dialog_started.connect(_on_dialog_started)
	DialogManager.dialog_finished.connect(_on_dialog_finished)
	DialogManager.dialog_next_requested.connect(_on_dialog_next_requested)
	hide()

func _input(event: InputEvent) -> void:
	if not visible:
		return
		
	if event.is_action_pressed("ui_accept") or event.is_action_pressed("mouse_left"):
		DialogManager.next_message()

func _on_dialog_started() -> void:
	show()

func _on_dialog_finished() -> void:
	hide()

func _on_dialog_next_requested(message: Dictionary) -> void:
	name_label.text = message.get("name", "???")
	text_label.text = message.get("text", "") 
